// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using NUnit.Framework;
using ValidationAspects.Exceptions;
using ValidationAspects.Factories;

namespace TestValidationAspects.Factories
{
	[TestFixture]
	public class TestMinimumLength
	{
		private static void Fail(int length, string actual)
		{
			Test.Throws<ValidateMinimumLengthException>(() => new MinimumLength {Length = length}.Create<string>().Invoke(actual, new MockValidationContext()),
			                                            new ValidateMinimumLengthException(length, actual.Length).Message);
		}

		private static void Pass(int length, string actual)
		{
			new MinimumLength {Length = length}.Create<string>().Invoke(actual, new MockValidationContext());
		}

		[Test]
		public void Test_MinimumLength()
		{
			Pass(0, string.Empty);
			Fail(1, string.Empty);
			Fail(5, "test");
			Pass(4, "test");
			Pass(3, "test");
		}

		[Test]
		public void Test_validation_skips_null_value()
		{
			Pass(1, null);
		}
	}
}